package com.phome.iservice.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.phome.idao.StudentDao;
import com.phome.iservice.StudentService;
import com.phome.model.Student;
import com.phome.type.FindType;

/**
 * 
 * 学生的服务类实现
 * @author ma
 *
 */
@Repository("ss")
public class StudentServiceImpl implements StudentService<Student> {

	private List<Student> list = null;
	
	@Resource(name="sessionFactory")
	private SessionFactory sessionFactory = null;
	
	@Resource(name="sdao")
	private StudentDao sdao;

	/*
	 * 
	 * 学生登录
	 * (non-Javadoc)
	 * @see com.phome.iservice.StudentService#login(java.lang.Object)
	 */
	@Override
	public boolean login(FindType type,Student s) {
		
		list = sdao.findByCoundition(type, s);
		
		if(list == null){
			
			return false;
		}else{
			
			return true;
		}
	}

	/*
	 * 学生注册
	 * (non-Javadoc)
	 * @see com.phome.iservice.StudentService#register(com.phome.type.FindType, java.lang.Object)
	 */
	@Override
	public boolean register(FindType type,Student s) {
		
		int i = 0;
		list = sdao.findByCoundition(type,s.getName());
		System.out.println(list.size()==0);
		System.out.println("是否正确");
		if(list.size() == 0){
			System.out.println(s.toString());
			i = sdao.add(s);
		}
		if(i > 0){
			
			return true;
		}else{
			return false;
		}
	}

	@Override
	public Student FindById(int id) {
		
		Student s = sdao.findById(id);
		return s;
	}

	@Override
	public List<Student> FindByCondition(FindType type,Student s) {
		// TODO Auto-generated method stub
		return null;
	}

	
}
